****



*-------------------------------------------------------------------------------
* Start with SC removals and merge in census data
*-------------------------------------------------------------------------------



*****

use "scremovals9-15.dta", clear


*-------------------------------------------------------------------------------
* merge in census data
*-------------------------------------------------------------------------------

merge m:1 state county using censusdata

*county tag
bysort state county: gen statecountytag = 1 if _n == 1

*are we missing any enforcement data in top ten percent?
tab _m if statecountytag == 1 & numberhispanic > 17896 & numberhispanic < .
*just baltimore; nothing to be done here because ICE doesn't distinguish between the two relevant counties


*-------------------------------------------------------------------------------
* How many of the removals do the largest cities by Hispanic population account for?
*-------------------------------------------------------------------------------

gen count = 1

*monthly totals by deport date
bysort month: egen monthlytotal=sum(count)

*state-county monthly totals
gen state_county = state + "_" + county
bysort state_county month: egen countymonthlytotal = sum(count)

*state_county total totals
bysort state_county: egen countytotal=sum(count)

*largest 10% of hispanic population accounts for 373994 -- over 80% of deportations
tabstat countytotal if statecountytag == 1 & numberhispanic > 17896 & numberhispanic < ., stat(sum)
disp 373994/454474

*calculate total hispanic population
egen temph = sum(numberhispanic) if statecountytag == 1 
su temph, f
assert r(mean) == 50477156
drop temph

*-------------------------------------------------------------------------------
* Add in policy dates
*-------------------------------------------------------------------------------

drop _m

merge m:1 state county using policies

*how many counties matched? 296
tab statecountytag if _m == 3

*size of hispanic population in top 10% of counties
egen temph = sum(numberhispanic) if statecountytag == 1 & numberhispanic > 17896 & numberhispanic < .
su temph, f
assert r(mean) == 44253940
drop temph

*number of removals in top 10% of counties 373994
count if numberhispanic > 17896 & numberhispanic < .
assert r(N) == 373994

*size of hispanic population in 296 matched counties
egen temph = sum(numberhispanic) if statecountytag == 1 & _m == 3
su temph, f
assert r(mean) == 43511744
drop temph

*number of removals in 296 matched counties -- more than 80% of all removals
count if _m == 3
assert r(N) == 369388
disp 369388/454474

*-------------------------------------------------------------------------------
* Graph of SC Removals Over Time Using All Data (before dropping nonmatching counties and collapsing)
*-------------------------------------------------------------------------------

*first drop extra counties from census
drop if departed_d == .
count
assert r(N) == 454474

*count interior number in 2014 and 2015
count if month > m(2013m12) & month < m(2016m1) & removal_current_program != "Border Patrol" ///
& removal_current_program != "Inspections - Air" & removal_current_program != "Inspections - Land" ///
& removal_current_program != "Inspections - Sea"
assert r(N) == 89661

*cap deportations
gen capcount = 1 if latest_apprehension_method == "287(g) Program" | ///
latest_apprehension_method == "CAP Local Incarceration" | latest_apprehension_method == "CAP State Incarceration" 

*make monthly total of state, local, 287g deportations 
bysort month: egen capmonthlytotal = sum(capcount)

*month tag
bysort month: gen monthtag = 1 if _n == 1
sort month

**check that numbers add up
tabstat monthlytotal if monthtag == 1, stat(sum)

***
**Fig. S1: Deportation Totals Over Time
***


twoway (lpoly monthlytotal month if monthtag == 1 & month <= m(2015m12)) ///
(lpoly capmonthlytotal month if monthtag == 1 & month <= m(2015m12)) , ///
 legend(order(1 "All Deportations With a Fingerprint Match to a State/Local Arrest" ///
 2 "Deportations Following Arrest by ICE Official at Jail" )) yti("Monthly Deportations") /// 
xti("Year") xlabel(588(12)672, noticks format(%tmCY)) ///
 xline(617, lpattern(dot))  xline(658, lpattern(dot)) xline(645, lpattern(dot)) ///
 text(1500 645 "CA Sanctuary Law", placement(v) orientation(vertical) size(small)) ///
  text(1500 617 "Morton Memo", placement(v) orientation(vertical) size(small)) ///
  text(7000 658 "Priority Enforcement", placement(v) orientation(vertical) size(small)) 
graph export "s1.pdf", replace

**
*save
**

save "scremovals9-15.dta", replace
